import middleWareApi from "../middleWareApi";

export default {
    emailResetPassword(user_name, password, code, success, fail){
        let uploadJson = {
            username: user_name,
            password: password,
            emailPassword: code
        }
        uni.request({
            url: middleWareApi.EMAIL_PASSWORD_RESET,
            method: "POST",
            header: {
                'Content-Type': 'application/json'
            },
            data: uploadJson,
            success: success,
            fail: fail
        })
    },

    emailSendForgetCode(user_name, success, fail){
        let uploadJson = {
            username: user_name,
        }
        uni.request({
            url: middleWareApi.EMAIL_FORGET_CODE,
            method: "POST",
            header: {
                'Content-Type': 'application/json'
            },
            data: uploadJson,
            success: success,
            fail: fail
        })
    },

    historyRecordDelete(user_name, upload_token, img_name, success, fail){
        let uploadJson = {
            userName: user_name,
            uploadToken: upload_token,
            imgName: img_name
        }
        uni.request({
            url: middleWareApi.HISTORY_IMG_DELETE,
            method: "POST",
            header: {
                'Content-Type': 'application/json'
            },
            data: uploadJson,
            fail: fail,
            success: success
        })
    },

    historyImgGet(user_name, upload_token, success, fail){
        let uploadJson = {
            userName: user_name,
            uploadToken: upload_token
        }
        uni.request({
            url: middleWareApi.HISTORY_IMG_GET,
            method: "POST",
            header: {
                'Content-Type': 'application/json'
            },
            data: uploadJson,
            fail: fail,
            success: success
        })
    },

    historyTokenGet(user_name, success, fail){
        let uploadJson = {
          userName: user_name
        }
        uni.request({
            url: middleWareApi.HISTORY_TOKEN_GET,
            method: "POST",
            header: {
                'Content-Type': 'application/json'
            },
            data: uploadJson,
            fail: fail,
            success: success
        })
    },

    historyInsert(user_name, upload_token, img_list, success, fail){
      let uploadJson = {
          userName: user_name,
          uploadToken: upload_token,
          imgList: img_list
      }

      uni.request({
          url: middleWareApi.HISTORY_INSERT,
          method: "POST",
          header: {
              'Content-Type': 'application/json'
          },
          data: uploadJson,
          fail: fail,
          success: success
      })
    },
    userLogin(user_name, password, success, fail) {
        let userData = {
            username: user_name,
            password: password
        }
        uni.request({
            url: middleWareApi.LOGIN,
            method: "POST",
            header: {
                'Content-Type': 'application/json'
            },
            data: userData,
            success: success,
            fail: fail
        })
    },
    userRegister(user_name, password, email, success, fail) {
        let userData = {
            username: user_name,
            password: password,
            email: email
        }
        uni.request({
            url: middleWareApi.REGISTER,
            method: "POST",
            header: {
                'Content-Type': 'application/json'
            },
            data: userData,
            success: success,
            fail: fail
        })
    }
}
